package com.example.controller;

import com.example.entity.DepartmentsEntity;
import com.example.service.DepartmentsService;
import com.example.utils.ReturnT;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/dep")
@Tag(name = "部门接口", description = "部门接口")
public class DepartmentsController {

    @Resource
    private DepartmentsService departmentsService;

    @GetMapping("/pageList")
    @Operation(summary = "查询 分页查询")
    public Map<String, Object> pageList(@RequestParam(required = false, defaultValue = "0") int offset,
                                        @RequestParam(required = false, defaultValue = "10") int pagesize) {
        return departmentsService.pageList(offset, pagesize);
    }

    @GetMapping("/load")
    @Operation(summary = "查询 根据主键 id 查询")
    public Object load(int id){
        return departmentsService.load(id);
    }

    @PutMapping("/insert")
    @Operation(summary = "插入")
    public Object insert(DepartmentsEntity departmentsEntity){
        System.out.println("Received departmentsEntity: " + departmentsEntity);
        return departmentsService.insert(departmentsEntity);

    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除")
    public Object delete(int id){
        return departmentsService.delete(id);
    }

    @PostMapping("/update")
    @Operation(summary = "更新")
    public Object update(DepartmentsEntity departmentsEntity){
        return departmentsService.update(departmentsEntity);
    }

    @GetMapping("/selectByCode")
    @Operation(summary = "通过部门code获取部门信息")
    public ReturnT<List<DepartmentsEntity>> selectByDepeartmentCode(String departmentCode) {
    	return departmentsService.selectByDepartmentCode(departmentCode);
    }
}
